home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1178 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP NEEDED: What the hell is wrong with my program?
  5. Date: 12 Jan 1996 00:44:54 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan11174454@qcd.lanl.gov>
  8. References: <4d1qmp$h43@carbon.cudenver.edu> <DTHORNTO.96Jan11125703@aplo266.spd.dsccc.com>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: dthornto@aplo266.spd.dsccc.com's message of 11 Jan 1996 18:57:03 GMT
  13.  
  14. --text follows this line--
  15. In article <DTHORNTO.96Jan11125703@aplo266.spd.dsccc.com>
  16. dthornto@aplo266.spd.dsccc.com (Duane Thornton) writes: 
  17.  
  18.        ptr-> name=(char *)malloc(strlen(str1));
  19.  
  20.                     ^^^^^This should be strlen(str1 + 1)
  21.    The length returned by 'strlen' does not include the terminator
  22.    (\0). Therefore the following 'strcpy' actually copies the terminator
  23.    outside of the memory reserved by the above 'malloc'.
  24.  
  25. strlen(str1 + 1) == strlen(str1) - 1 (unless strlen(str1) == 0) :-)
  26.  
  27. Cheers
  28. Tanmoy
  29. --
  30. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  31. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  32. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  33. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  34. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  35. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  36.